package org.or5e.odes.core.folder;

import java.io.File;
import java.io.IOException;
import java.util.InvalidPropertiesFormatException;
import java.util.Properties;

import org.or5e.odes.core.BaseObject;

public class ScanFolderServiceImpl extends BaseObject implements ScanFolderService {
	@SuppressWarnings("unused")
	private static Boolean _isServiceRunning = Boolean.FALSE;
	private Properties _props = null;
	static {
	}
	public ScanFolderServiceImpl() {
	}
	public void init(String configFile) {
		_props = new Properties();
		try {
			_props.loadFromXML(ClassLoader.getSystemResourceAsStream(configFile));
		} catch (InvalidPropertiesFormatException e) {
			e.printStackTrace(System.out);
		} catch (IOException e) {
			e.printStackTrace(System.out);
		}
	}

	public void scanForVideo() {
		_isServiceRunning = Boolean.TRUE;
		debug("Running Scan for Video is started...");
		ScanFolderHelper.scanVideo(new File(_props.getProperty("video-folder-name")));
		_isServiceRunning = Boolean.FALSE;
	}
	public void scanForMusic() {
		_isServiceRunning = Boolean.TRUE;
		
		_isServiceRunning = Boolean.FALSE;
	}

	public void scanForImage() {
		_isServiceRunning = Boolean.TRUE;
		
		_isServiceRunning = Boolean.FALSE;
	}

	public void close() {

	}
	public String getProperty(String key) {
		return _props.getProperty(key);
	}
	@Override protected String getName() {
		return "ScanFolderServiceImpl";
	}
	
	public static void main(String[] args) {
		ScanFolderService _service = new ScanFolderServiceImpl();
		_service.init("config/folder-config.xml");
		System.out.println("Done..."+_service.getProperty("video-folder-name"));
		_service.scanForVideo();
	}
}